﻿using System;
using Caliburn.Micro;
using MIXer.Contracts;

namespace MIXer.ViewModels
{
    public class Tab : PropertyChangedBase, ITab
    {
        #region Fields
        private bool _enabled = true;
        private string _busyMessage;
        private string _windowTitle;
        private bool _inProgress;
        private int _currentProgress;
        #endregion

        #region Constructors
        public Tab(string displayName)
        {
            DisplayName = displayName;
            WindowTitle = displayName;
        }
        #endregion

        #region Methods
        public void WhileBusy(System.Action @do = null, string show = "Busy")
        {
            if (@do == null)
                throw new ArgumentNullException("@do", "Missing the action that's going to make screen busy");

            Busy(show);
            @do();
            Free();
        }
        public virtual void Busy(string message)
        {
            IsEnabled = false;

            if (!String.IsNullOrEmpty(message))
            {
                BusyMessage = message;
            }
        }
        public virtual void Free()
        {
            IsEnabled = true;
            BusyMessage = null;
        }
        #endregion

        #region Properties
        public string DisplayName { get; set; }
        public bool IsEnabled
        {
            get { return _enabled; }
            private set
            {
                _enabled = value;

                NotifyOfPropertyChange(() => IsEnabled);
            }
        }
        public string BusyMessage
        {
            get { return _busyMessage; }
            private set
            {
                _busyMessage = value;

                NotifyOfPropertyChange(() => BusyMessage);
            }
        }
        public string WindowTitle
        {
            get { return _windowTitle; }
            set
            {
                _windowTitle = value;

                NotifyOfPropertyChange(() => WindowTitle);
            }
        }
        public bool InProgress
        {
            get { return _inProgress; }
            set
            {
                _inProgress = value;

                NotifyOfPropertyChange(() => InProgress);
            }
        }
        public int CurrentProgress
        {
            get { return _currentProgress; }
            set
            {
                _currentProgress = value;

                NotifyOfPropertyChange(() => CurrentProgress);
            }
        }
        #endregion
    }
}
